﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class OnErrorStatement : Statement
{
    private readonly SyntaxToken _errorKeywordToken;

    private readonly SyntaxToken _onKeywordToken;


    private GotoStatement? _jumpStatement;
    private ResumeStatement? _resumeStatement;

    internal OnErrorStatement(SyntaxToken onKeywordToken, SyntaxToken errorKeywordToken, SyntaxNode? parent) :
        base(SyntaxKinds.OnErrorStatement, parent)
    {
        SetChildField(ref _onKeywordToken, onKeywordToken);
        SetChildField(ref _errorKeywordToken, errorKeywordToken);
    }


    public SyntaxToken OnKeywordToken => _onKeywordToken;

    public SyntaxToken ErrorKeywordToken => _errorKeywordToken;


    public GotoStatement? JumpStatement => _jumpStatement;

    public ResumeStatement? ResumeStatement => _resumeStatement;


    public void Update(GotoStatement jumpStatement)
    {
        SetChildNullableField(ref _jumpStatement, jumpStatement);
    }


    public void Update(ResumeStatement resumeStatement)
    {
        SetChildNullableField(ref _resumeStatement, resumeStatement);
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, OnKeywordToken, ErrorKeywordToken, JumpStatement, ResumeStatement);
    }
}


public static partial class NodeFactory
{
    public static OnErrorStatement CreateOnErrorStatement(SyntaxNode? parent, SyntaxToken onKeyword,
        SyntaxToken errorKeyword)
    {
        Debug.Assert(onKeyword.IsNode(SyntaxKinds.OnKeywordToken));
        return new OnErrorStatement(onKeyword, errorKeyword, parent);
    }
}